/* 
 * File:   mss.h
 * Author: samik
 *
 * Created on 18 November, 2008, 9:15 AM
 */
#include "simulator.h"
#ifndef _MSS_H
#define	_MSS_H

#ifdef	__cplusplus
extern "C" {
#endif
#define NO_MHS 10
#define NO_MESSAGES 10
    typedef struct {
        int id;
        int no_of_mhs; //max. # of MHs that can connect to the MSS
        int mhs[NO_MHS]; //connected MHs
    } Mobile_support_station;

    /* Structure thread_data:
     * Contains all data that are to be passed to the function runs in
     * receive thread.
     */
    struct thread_data {
        int sd;
        int mss_id;
        int src_node_id;
    };

    /*
     * Function: receive_msg() - This function is executed as a separate thread
     *          to receive msgs indepedently from MH and send them to the
     *          Message Queue for the sender thread to read.
     */
    static void *receive_msgs_from_mh(void *tdarg);

    /*
     * Function: receive_msg() - This function is executed as a separate thread
     *          to receive msgs indepedently from MSS and send them to the
     *          Message Queue for the sender thread to read.
     */
    static void *receive_msgs_from_mss(void *tdarg);

    /*
     * Function: connect_to_mss()
     * This function creates a TCP connection to another instance of an MSS.
     */
    int connect_to_mss(int SERVER_MSS);

    /*
     * Function: mss_server()
     * Starts a TCP server for other MSSs and MHs to connect to. For each
     * MH or MSS it forks a child process to handle sending or receiving of
     * messages.
     */
    int mss_server();

    
#ifdef	__cplusplus
}
#endif

#endif	/* _MSS_H */

